package com.example.myapplication;

import android.content.Context;
import android.widget.Toast;

public class ToastUtil {

    private static Toast toast = null;

    public static void show(Context context, String text) {

        //Toast的普通用法
        if (toast != null) {
            //解决多个Toast重叠显示的问题
            toast.cancel();
        }
        toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
        toast.show();

    }

    public static void show(Context context, String text, int postion) {

        //Toast的普通用法
        if (toast != null) {
            //解决多个Toast重叠显示的问题
            toast.cancel();
        }
        toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
        toast.setGravity(postion, 0, 0);
        toast.show();

    }

}
